<?php
/**
 * @version		$Id: example.php 14401 2010-01-26 14:10:00Z louis $
 * @package		Joomla
 * @subpackage	Content
 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

/**
 * Example Content Plugin
 *
 * @package		Joomla
 * @subpackage	Content
 * @since 		1.5
 */
class plgContentPublishToWall extends JPlugin
{

	/**
	 * Constructor
	 *
	 * For php4 compatability we must not use the __constructor as a constructor for plugins
	 * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
	 * This causes problems with cross-referencing necessary for the observer design pattern.
	 *
	 * @param object $subject The object to observe
	 * @param object $params  The object that holds the plugin parameters
	 * @since 1.5
	 */
	function plgContentPublishToWall( &$subject, $params )
	{
		parent::__construct( $subject, $params );
	}

	/**
	 * Example after save content method
	 * Article is passed by reference, but after the save, so no changes will be saved.
	 * Method is called right after the content is saved
	 *
	 *
	 * @param 	object		A JTableContent object
	 * @param 	bool		If the content is just about to be created
	 * @return	void
	 */
	 
	function onAfterContentSave( &$article, $isNew )
	{
		require_once(JPATH_ROOT.DS.'components'.DS.'com_community'.DS.'libraries'.DS.'core.php');
		$app = &JFactory::getApplication();
		$my		= CFactory::getUser();
		
		$act = new stdClass();
		$act->cmd 		= 'profile';
		$act->actor   	= $my->id;
		$act->target  	= 0;
		$act->title	  	= "{actor} ha inserito l'articolo <a href=_QQQ_{content_url}_QQQ_>" . $article->title . "</a>";

		$act->content	= '';
		$act->app		= 'profile';
		
		// Allow comment on the post
		$act->comment_type	= 'profile.content';
		$act->comment_id	= $article->id;
			
		// Allow like on the post
		$act->like_type	= 'profile.content';
		$act->like_id	= $article->id;		
		
		//var_dump($article->title);exit;
		

		$params = new CParameter('');
		$params->set('content_url' , 'index.php?option=com_content&view=article&id=' . $article->id );


		// Add activity logging
		CFactory::load ( 'libraries', 'activities' );
		CActivityStream::add( $act, $params->toString() );
		
		
		return true;
	}

}
